﻿package com.view 
{
	import adobe.utils.CustomActions;
	import flash.display.MovieClip;
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author zheng sir
	 */
	public class BgMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "bgMediator_name";
		public static const BGCHANGED:String = "bgMediator_changed";
		public static const INITBG:String = "bgMediator_initBg";
		private static const BGNUM:int = 1;//初始显示第一个页面
		private static const BGTOTAL:int = 5;//总数
		
		public function BgMediator(mediatorName:String = null, viewComponent:Object = null) 
		{
			super(mediatorName, viewComponent);
			
		}
		override public function onRegister():void 
		{
			super.onRegister();
			viewComponent.bg.stop();
			viewComponent.bg.num = BGNUM;
			viewComponent.bg.gotoAndStop(BGNUM);
		}
		override public function listNotificationInterests():Array 
		{
			return [BGCHANGED,INITBG];
		}
		override public function handleNotification(notification:INotification):void 
		{
			super.handleNotification(notification);
			var name:String = notification.getName();
			switch(name) {
				case INITBG:
					var bg:MovieClip = viewComponent.bg as MovieClip;
					bg.num = 1;
					bg.gotoAndStop(1);
					break;
				case BGCHANGED:
					changedBg();
					break;
			}
		}
		private function changedBg():void {
			var bg:MovieClip = viewComponent.bg as MovieClip;
			var num:int = bg.num;
			num++;
			if (num <= BGTOTAL) {
				
			}else {
				num = 1;
			}
			bg.num = num;
			bg.gotoAndStop(num);
		}
		
	}

}